package com.shujia.mr.hw.home2;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

public class Home2Driver {
    public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException {
        Job job = Job.getInstance(new Configuration());
        job.setJarByClass(Home2Driver.class);
        job.setJobName("home2");

        job.setMapperClass(Home2Mapper.class);
        job.setReducerClass(Home2Reducer.class);

        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(Text.class);
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(Text.class);

        // 设置自定义分区类
        // PARTITIONER_CLASS_ATTR = "mapreduce.job.partitioner.class";
        job.setPartitionerClass(Home2Partition.class);

        // 由于分区数为2，那么需要设置Reduce的个数也为2
        job.setNumReduceTasks(3);

        FileInputFormat.addInputPath(job,new Path("output/count"));
        FileOutputFormat.setOutputPath(job,new Path("output/home2"));

        job.waitForCompletion(true);

    }
}
